package com.mcm.vistas;

import java.awt.Cursor;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class MainPanel extends JFrame implements ActionListener
{

	private static final long serialVersionUID = -4808681369438344080L;
	VistaProductos vp = null;
	JButton botonIntro;

	public MainPanel() 
	{
		setTitle("Matafuegos MCM");
	    setSize(500, 400);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    getContentPane().setLayout(new BoxLayout(this.getContentPane(),BoxLayout.Y_AXIS));
	    setResizable(false);
	    
	    mostrarBotonIntro();
	}
	
	private void mostrarBotonIntro()
	{
		botonIntro = new JButton();
		try {
			Image img = ImageIO.read(getClass().getResource("/imagenes/Logo2.jpg"));
			Image newimg = img.getScaledInstance(500, 360, java.awt.Image.SCALE_SMOOTH);
			img = null;
			ImageIcon ic = new ImageIcon(newimg);
			botonIntro.setIcon(ic);
			botonIntro.setCursor(new Cursor(Cursor.HAND_CURSOR));
			botonIntro.addActionListener(this);
			botonIntro.setName("botonIntro");
		} catch (IOException ex) {
		}
		
//		button.setSize(new Dimension(400, 180));
		
		add(botonIntro);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) 
	{
		JButton button = (JButton)e.getSource();
		int x = getContentPane().getComponentZOrder(button);
//		System.out.println(x);

		if(((JButton)e.getSource()).getName().equals("botonIntro"))
		{
			vp = new VistaProductos();
		    add(vp);
//	        pack();
	        this.getContentPane().remove(button);
//	        this.repaint();
	        this.validate();
		}
	}
}
